package www;

import java.util.Random;

public class GuiTu {
	public static void main(String args[]) {
        Wugui wu = new Wugui();
        Tuzi tu = new Tuzi();
        tu.setName("兔子");
        wu.setName("乌龟");

        tu.start();
        wu.start();
        System.out.println("兔子、乌龟跑起来了");
    }
}

class Wugui extends Thread {
    int meters = 0;
    Random pp = new Random();
    int r1 = pp.nextInt(1)+1;
    int len=pp.nextInt(1)+2;
    public void run() {
        while (true) {
            String name = Thread.currentThread().getName();
         
            if (meters<20) {
                meters+=len;
                System.out.println(name + "跑了" + meters + "米");
                System.out.println(name + "休息了"+r1+"s");
                    try {
                        Thread.sleep(r1*1000);  //间隔时间
                    } catch (InterruptedException e) {
                    }

                } 
                     

                
        else {
                System.out.println("乌龟到达终点！！！");         
                return;
            }
        }
    }
}

class Tuzi extends Thread {
    int meters = 0;
    public void run() {
    	   Random pp = new Random();
    	 int r1 = pp.nextInt(1)+5;
    	    int len=pp.nextInt(1)+7;
        while (true) {

            String name = Thread.currentThread().getName();

            if (meters<20) {
                meters += len;
                System.out.println(name + "跑了" + meters + "米");
                           
                    System.out.println(name + "休息了"+r1+"s");
                    try {
                        Thread.sleep(r1*1000);  //间隔时间
                    } catch (InterruptedException e) {
                    }
                } 
                    
                
            
        else  {
                System.out.println("兔子到达终点！！！");
                return;
            }
        }

    }
}

